<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>demo</title>
  </head>
  <body>
    <div id="app">
      <!-- v-model是用来做双向数据绑定的，记得：只有表单能用 -->
      
      <!-- <p contenteditable="true" v-model="inf.test">这是一个可编辑的段落。</p> -->
      <form action="#">
        姓名(文本)：<input type="text" v-model="inf.name" /> <br /><br />
        性别(单选按钮)：

        <input name="sex" type="radio" value="man" v-model="inf.sex" />男
        <input name="sex" type="radio" value="woman" v-model="inf.sex" />女
        <br /><br />

        技能(多选框)：
        <input
          type="checkbox"
          name="skills"
          value="java"
          v-model="inf.skill"
        />Java开发
        <input
          type="checkbox"
          name="skills"
          value="vue"
          v-model="inf.skill"
        />Vue.js开发
        <input
          type="checkbox"
          name="skills"
          value="python"
          v-model="inf.skill"
        />Python开发 <br /><br />
        城市(下拉框)：
        <select name="citys" v-model="inf.city">
          <option value="bj">北京</option>
          <option value="gz">广州</option>
          <option value="fs">佛山</option>
          <option value="dg">东莞</option>
        </select>
        <br /><br />
        说明(多行文本)：<textarea
          cols="30"
          rows="5"
          v-model="inf.msg"
        ></textarea>
        <br /><br />
        <button type="submit" @click.prevent="pushMes">提交</button>
      </form>
    </div>
  </body>
  <script src="../node_modules/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el: "#app",
      data: {
        // num: 0,
        // arr: [1, 2, 3],

        inf: {
          name: "",
          sex: "woman",
          skill: ["python", "vue"],
          city: "gz",
          msg: "",
          test: "",
        },
        // good: [
        //   {
        //     gid: 1,
        //     gname: "苹果",
        //   },
        //   {
        //     gid: 2,
        //     gname: "小米",
        //   },
        // ],
      },
      methods: {
        pushMes() {
          //点击获取所有的表单数据提交  ajax
          console.log(this.inf, "数据提交");
        },
      },

      watch: {
        //普通的写法：函数的写法，只能侦听一层数据
        // num(newval) {},
        // arr(newarr) {},
        // good: {
        //   deep: true, //深度监听
        //   handler(newval) {},
        // },
        inf: {
          //深度监听
          deep: true,
          handler(newval) {
            console.log(newval, "我变了");
          },
        },
      },
    });
  </script>
</html>
